// 欢乐谷送门票
$(function(){
	
	// var userId = "14606216427971026";
	var activityId = "98";
	
	if (isIOS()) {
		var userId = getQueryStr("userId");
	}else{
		var userId = JavascriptInterface.getUserId();
	}
	
	getShareCode(userId, activityId);
	
	$("#btnShareCode").bind("click", function(){		
		shareCode();
	});
	
});

// 分享活动送欢乐谷门票
function shareCode() {

	var title = "叮叮约车";
	var content = "我正在使用叮叮约车，一起来搭顺风车吧";
	
	//判断设备并调用返回
	if (isIOS()) {
		 // var str = {"title":'叮叮约车',"content":"我正在使用叮叮约车，一起来搭顺风车吧","url":"http://www.baidu.com"};
		
		var userId = getQueryStr("userId");
		var activityId = "98";
		var shareCode = $("#shareCode").text();  // 分享码
		var url = baseUrl + "page/user/register.html?userId="+userId+"&activityId="+activityId+"&shareCode="+shareCode+"";
		
		window.webkit.messageHandlers.takeActivityShare.postMessage({"title": title, "content": content,"url":url});
		// window.webkit.messageHandlers.takeActivityShare.postMessage("123456");
	} else {
		// 获取活动代码
		var userId = JavascriptInterface.getUserId();
		var activityId = "98";
		var shareCode = $("#shareCode").text();	// 分享码
		var url = baseUrl + "page/user/register.html?userId="+userId+"&activityId="+activityId+"&shareCode="+shareCode+"";

		JavascriptInterface.takeActivityShare(title, content, url);
	}
}

// 获取分享码
function getShareCode(userId,activityId){
	
	$.ajax({
		async: false,
        type: "post",
        url : "activityShareAction!getShareCode.action",
        data: {
        	'userId':userId,
        	"activityId":activityId
        },
        dataType: "text",
        success: function(data){
        	$("#shareCode").html(data);
        }
    });
	
}
